<?php


namespace app\api\service;

use app\api\model\Cart as CartModel;

class Cart
{
    public static function create($user_id, $flag, $product_id, $sku_id, $num)
    {
        $data = [
            'user_id' => $user_id,
            'product_id' => $product_id,
            'sku_id' => $sku_id,
            'flag'=> $flag,
            'num'=> $num,
            'is_del' => 0,
        ];

        try{
            CartModel::create($data);
        }catch (\Exception $e){
            return false;
        }
        return true
    }

    public static function delete($user_id, $flag, $product_id, $sku_id)
    {
        try{
            CartModel::destroy(function($query) use ($user_id, $product_id, $sku_id) {
                $query->where(['user_id'=>$user_id, 'product_id'=>$product_id, 'sku_id'=>$sku_id]);
            });
        }catch (\Exception $e){
            return false;
        }
        return true;
    }
}